package com.leyou.item.service;

import com.leyou.common.enums.ExceptionEnum;
import com.leyou.common.exception.LyException;
import com.leyou.common.utils.BeanHelper;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.pojo.dto.SpecParamDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Service
public class SpecParamService {

    @Autowired
    private SpecParamMapper specParamMapper;

    /*根据参数数组id,查询参数列表*/
    public List<SpecParamDTO> querySpecParamsByGroupId(Long pid, Long cid, Boolean searching) {
        SpecParam specParam = new SpecParam();
        specParam.setGroupId(pid);
        specParam.setCid(cid);
        //TODO: 添加是否可用于搜索的条件
        specParam.setSearching(searching);
        List<SpecParam> select = specParamMapper.select(specParam);
        if (CollectionUtils.isEmpty(select)){
            throw new LyException(ExceptionEnum.RESOURCE_NOT_FOUND);
        }
        return BeanHelper.copyWithCollection(select,SpecParamDTO.class);
    }
}
